﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PwdMgr.DataAccess.Exps;

namespace DataAccess.Tests
{
    [TestClass]
    public class ExpBrowserTest
    {
        [TestMethod]
        public void TestBasic()
        {
            ExpBrowser browser = new ExpBrowser();

            BinaryExp exp = Exp.Binary(
                Exp.Constants("name"),
                "==",
                Exp.Constants("aaa"));

            string value = browser.Browse(exp);

            Assert.AreEqual("name == 'aaa'", value);
        }

        [TestMethod]
        public void TestAdvanced()
        {
            Exp exp = Exp.Binary(
                Exp.Binary(
                    Exp.Binary(
                        Exp.Constants("a"),
                        "=",
                        Exp.Constants("a")),
                    "and",
                    Exp.Binary(
                        Exp.Constants("b"),
                        "!=",
                        Exp.Constants("b"))),
                "and",
                Exp.Binary(
                    Exp.Binary(
                        Exp.Constants("c"),
                        ">=",
                        Exp.Constants(3)),
                    "or",
                    Exp.Binary(
                        Exp.Constants("d"),
                        "is not",
                        Exp.Constants(null))));

            string value = new ExpBrowser().Browse(exp);

            Assert.AreEqual("(((a = 'a') and (b != 'b')) and ((c >= 3) or (d is not null)))", value);
        }
    }
}
